package com.example.reflectiondemo;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @program my-project-model
 * @description:
 * @author: lee
 * @create: 2022/09/23 16:06
 */
public class Apple {
    public int price;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    //    public static void main(String[] args) throws Exception{
//        //正常的调用
//        Apple apple = new Apple();
//        apple.setPrice(5);
//        System.out.println("Apple Price:" + apple.getPrice());
//        //使用反射调用
//        Class clz = Class.forName("com.example.reflectiondemo.Apple");
//        Method setPriceMethod = clz.getMethod("setPrice", int.class);
//        Constructor appleConstructor = clz.getConstructor();
//        Object appleObj = appleConstructor.newInstance();
//        setPriceMethod.invoke(appleObj, 14);
//        Method getPriceMethod = clz.getMethod("getPrice");
//        System.out.println("Apple Price:" + getPriceMethod.invoke(appleObj));
//    }
    public static void main(String[] args) {
        List<Student> list = new ArrayList<Student>();
        list.add(new Student("xiaom",18));
        list = Collections.unmodifiableList(list);
        System.out.println(list.get(0));
        System.out.println(list.add(new Student("xx",5)));
    }
}
